#include "TransportImpl.h"


TransportImpl::TransportImpl(void)
{
	m_mid_SendPacket = 0;
	m_mid_SendRTCPPacket = 0;
}


TransportImpl::~TransportImpl(void)
{
}

bool TransportImpl::init_jni(JNIEnv* env)
{
	bool result = false;

	do 
	{
		m_mid_SendPacket = (env)->GetMethodID(m_cls, "sendPacket", "(I[B)V");
		if(!m_mid_SendPacket)
			break;

		m_mid_SendRTCPPacket = (env)->GetMethodID(m_cls, "sendRTCPPacket", "(I[B)V");
		if(!m_mid_SendRTCPPacket)
			break;

		result = true;

	} while (false);

	return result;
}

int TransportImpl::SendPacket(int channel, const void *data, int len)
{
	int result = 0;
	JNIEnv* env = 0;
	if(before(&env))
	{
		result = (env)->CallIntMethod(m_obj, m_mid_SendPacket, 
			channel, JniHelper::c2j_bytes(env, (unsigned char*)data, len));
		after(env);
	}
	return result;
}

int TransportImpl::SendRTCPPacket(int channel, const void *data, int len)
{
	int result = 0;
	JNIEnv* env = 0;
	if(before(&env))
	{
		result = (env)->CallIntMethod(m_obj, m_mid_SendRTCPPacket, 
			channel, JniHelper::c2j_bytes(env, (unsigned char*)data, len));
		after(env);
	}
	return result;
}
